<!DOCTYPE html>
<html lang="en-US">
    <head>
        <title>Object::HashBase - Build hash based classes. - metacpan.org</title>
        <link rel="preload" as="fetch" href="https://metacpan.org/account/login_status" crossorigin="anonymous" />
        <link href="https://metacpan.org/_assets/b8ccceeed47a0652049703d99326a9cea4933443.css" rel="stylesheet" type="text/css">
        <script src="https://metacpan.org/_assets/6bfedafe2d7caa915b7d84f61b45936818e3242e.js" type="text/javascript" defer></script>
        <link rel="alternate" type="application/rss+xml" title="Recent CPAN Uploads of Object-HashBase - MetaCPAN" href="https://metacpan.org/dist/Object-HashBase/releases.rss" />
        <link rel="canonical" href="./Object::HashBase.html" />
        <meta name="description" content="Build hash based classes." />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5">
        <link rel="shortcut icon" href="https://metacpan.org/static/icons/favicon.ico">
        <link rel="apple-touch-icon" sizes="152x152" href="https://metacpan.org/static/icons/apple-touch-icon.png">
        <link rel="search" href="https://metacpan.org/static/opensearch.xml" type="application/opensearchdescription+xml" title="MetaCPAN">
        <script>
          (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
          (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
          })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

          (function(skey, ga_id){
            ga('create', ga_id, {
              siteSpeedSampleRate : 100,
              storage             : 'none',
              clientId            : localStorage.getItem(skey)
            });
            ga(function(tracker) {
              localStorage.setItem(skey, tracker.get('clientId'));
            });
            ga('send', 'pageview');
          })('ga:clientId', 'UA-27829474-1');
        </script>
<meta name="twitter:card"        content="summary" />
<meta name="twitter:url"         content="https://metacpan.org/pod/Object::HashBase" />
<meta name="twitter:title"       content="Object::HashBase" />
<meta name="twitter:description" content="Build hash based classes." />
<meta name="twitter:site"        content="metacpan" />
    </head>
    <body>
        <nav class="navbar navbar-default" role="navigation">
            <div class="header-logo-large hidden-xs">
              <a href="https://metacpan.org/" tabindex="0">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#logo" />
                </svg>
              </a>
            </div>
            <div class="header-logo-icon visible-xs">
              <a href="https://metacpan.org/">
                <svg class="logo" aria-label="MetaCPAN">
                  <use class="logo" href="/static/images/metacpan-logo.svg#dots" />
                </svg>
              </a>
            </div>
            <ul class="nav navbar-nav menu-items hidden-xs hidden-sm">
              <li><a href="https://metacpan.org/about">About</a></li>
              <li><a href="https://metacpan.org/about/sponsors">Sponsor</a></li>
              <li><a href="https://grep.metacpan.org/">grep::cpan</a></li>
              <li><a href="https://metacpan.org/recent">Recent</a></li>
              <li><a href="https://metacpan.org/about/faq">FAQ</a></li>
              <li><a href="https://metacpan.org/tools">Tools</a></li>
              <li><a href="https://fastapi.metacpan.org/">API</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <button type="button" class="searchbar-btn visible-xs visible-sm">
                    <i class="fa fa-search button-fa-icon"></i>
                </button>
                <form action="https://metacpan.org/search" class="searchbar-form visible-md visible-lg search-form form-horizontal">
                   <input type="hidden" name="size" id="metacpan_search-size" value="20">
                  <div class="form-group">
                      <div class="search-group">
                        <i class="fa fa-search"></i>
                        <input type="text" name="q" placeholder="Search the CPAN" size="41" autocorrect="off" autocapitalize="off" spellcheck="false" id="metacpan_search-input" class="form-control" value="">
                      </div>
                  </div>
                </form>
                    <li class="icon-slidepanel visible-xs visible-sm">
                      <button data-toggle="slidepanel" data-target=".slidepanel">
                        <span class="button-fa-icon">
                          <i class="fa fa-bars slidepanel-open"></i>
                          <i class="fa fa-times slidepanel-close"></i>
                        </span>
                      </button>
                    </li>
                <form action="https://metacpan.org/account/logout" method="POST" id="metacpan-logout"></form>
                <li class="dropdown logged_in" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon logged-in-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="https://metacpan.org/account/identities">Identities</a></li>
                        <li><a href="https://metacpan.org/account/profile">Profile</a></li>
                        <li><a href="https://metacpan.org/account/favorite/list">Favorites</a></li>
                        <li>
                            <a href="./Object::HashBase.html#" type="button" onclick="$('#metacpan-logout').submit(); return false">
                              Logout
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_out" style="display: none;">
                    <button type="button" class="dropdown-toggle" data-toggle="dropdown">
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                      <i class="fas fa-chevron-down"></i>
                    </button>
                    <ul class="dropdown-menu">
                        <li>
                            <a href="https://metacpan.org/login/github">
                                <i class="fab fa-github fa-fw"></i>
                                GitHub
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/twitter">
                                <i class="fab fa-twitter fa-fw"></i>
                                Twitter
                            </a>
                        </li>
                        <li>
                            <a href="https://metacpan.org/login/google">
                                <i class="fab fa-google fa-fw"></i>
                                Google
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="dropdown logged_placeholder">
                    <button>
                      <i class="fa fa-user button-fa-icon" aria-hidden="true"></i>
                    </button>
                </li>
            </ul>
        </nav>
        <div class="page-content ">
          <!--
          <div class="top-notify-banner">
            <i class="fas fa-info-circle"></i>
          </div>
          -->
          <nav class="sidebar">
            <div class="slidepanel">
              <ul class="nav-list ">
    <li class="nav-header no-margin-top">
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The date that this version of Object-HashBase was released.">
      <span class="relatize">23 Oct 2023 04:53:39 UTC</span>
    </li>
  <li>
    Distribution: <a href="https://metacpan.org/dist/Object-HashBase">Object-HashBase</a>
  </li>
  <li>
    Module version: 0.010
  </li>
  <li>
    <a data-keyboard-shortcut="g s" href="https://metacpan.org/dist/Object-HashBase/source/lib/Object/HashBase.pm">Source</a>
    (<a href="https://metacpan.org/dist/Object-HashBase/source/lib/Object/HashBase.pm?raw=1">raw</a>)
  </li>
  <li>
    <a data-keyboard-shortcut="g b" href="https://metacpan.org/dist/Object-HashBase/source/lib/Object">Browse</a>
    (<a href="https://metacpan.org/dist/Object-HashBase/source/lib/Object?raw=1">raw</a>)
  </li>
    <li>
      <a data-keyboard-shortcut="g c" href="https://metacpan.org/dist/Object-HashBase/changes">Changes</a>
    </li>
    <li>
      <a class="nopopup" href="https://metacpan.org/dist/Object-HashBase/contribute">How to Contribute</a>
    </li>
    <li>
        <a rel="noopener nofollow" data-keyboard-shortcut="g r" href="https://github.com/Test-More/Object-HashBase">Repository</a>
    </li>
    <li>
      <a rel="noopener nofollow" data-keyboard-shortcut="g i" href="http://github.com/Test-More/Object-HashBase/issues">Issues</a>
      (0)
    </li>
    <li>
      <a rel="noopener nofollow" href="http://matrix.cpantesters.org/?dist=Object-HashBase+0.010" title="Matrix">Testers</a>
        <span title="(pass / fail / na)">(<a rel="noopener nofollow" href="https://www.cpantesters.org/distro/O/Object-HashBase.html?oncpan=1&amp;distmat=1&amp;version=0.010&amp;grade=2" style="color: #090">455</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/O/Object-HashBase.html?oncpan=1&amp;distmat=1&amp;version=0.010&amp;grade=3" style="color: #900">0</a> / <a rel="noopener nofollow" href="https://www.cpantesters.org/distro/O/Object-HashBase.html?oncpan=1&amp;distmat=1&amp;version=0.010&amp;grade=4">0</a>)</span>
    </li>
    <li>
      <a rel="noopener nofollow" href="http://cpants.cpanauthors.org/release/EXODIST/Object-HashBase-0.010">Kwalitee</a>
    </li>
    <li>
      <div class="ttip" data-toggle="tooltip" data-placement="bottom" title="The # people with an indexing permission on Object-HashBase who have released something to CPAN in the last 2 years (i.e. the # people likely able to release critical fixes in a timely manner)">
      Bus factor: 1
      </div>
    </li>
    <li>
      License: perl_5
    </li>
    <li>
      Perl: v5.8.1
    </li>
    <li class="nav-header">Activity</li>
    <li>
<div class="activity-graph">
    <img src="https://metacpan.org/dist/Object-HashBase/activity.svg?res=month" />
    <div class="comment">24 month</div>
</div>
    </li>
    <li class="nav-header">Tools</li>
    <li>
      <a itemprop="downloadUrl" href="https://cpan.metacpan.org/authors/id/E/EX/EXODIST/Object-HashBase-0.010.tar.gz">
      Download (<span itemprop="fileSize">20.04KB</span>)</a>
    </li>
    <li>
      <a href="https://explorer.metacpan.org/?url=%2Fmodule%2FEXODIST%2FObject-HashBase-0.010%2Flib%2FObject%2FHashBase.pm">
        MetaCPAN Explorer
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Object-HashBase/permissions">
        Permissions
      </a>
    </li>
    <li>
      <a href="https://metacpan.org/dist/Object-HashBase/releases.rss">
        Subscribe to distribution
      </a>
    </li>
    <li>
      <button class="btn btn-link" data-toggle="modal" data-target="#metacpan_install-instructions-dialog">
        Install Instructions
      </button>
    </li>
    <li>
      <form action="https://metacpan.org/search">
        <input type="hidden" name="q" value="dist:Object-HashBase">
        <input type="search" name="q" placeholder="Search distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
      </form>
    </li>
    <li>
      <form action="https://grep.metacpan.org/search">
        <input type="hidden" name="qd" value="Object-HashBase">
        <input type="hidden" name="source" value="metacpan">
        <input type="search" name="q" placeholder="grep distribution" class="form-control tool-bar-form">
        <input type="submit" style="display: none">
     </form>
    </li>
    <li class="version-jump">
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Object/HashBase.pm&#39;" class="form-control tool-bar-form">
  <option disabled selected>Jump to version</option>
<option
  disabled
  value="EXODIST/Object-HashBase-0.010"
>0.010
  (EXODIST on 2023-10-23)</option>
<option
  
  value="EXODIST/Object-HashBase-0.009"
>0.009
  (EXODIST on 2020-01-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="EXODIST/Object-HashBase-0.008"
>0.008
  (EXODIST on 2019-09-24)</option>
<option
  
  value="EXODIST/Object-HashBase-0.007"
>0.007
  (EXODIST on 2019-09-19)</option>
<option
  
  value="EXODIST/Object-HashBase-0.006"
>0.006
  (EXODIST on 2017-10-21)</option>
<option
  
  value="EXODIST/Object-HashBase-0.005"
>0.005
  (EXODIST on 2017-02-11)</option>
<option
  
  value="EXODIST/Object-HashBase-0.004-TRIAL"
>0.004-TRIAL DEV
  (EXODIST on 2017-02-10)</option>
<option
  
  value="EXODIST/Object-HashBase-0.003"
>0.003
  (EXODIST on 2016-12-11)</option>
<option
  
  value="EXODIST/Object-HashBase-0.002"
>0.002
  (EXODIST on 2016-12-09)</option>
<option
  
  value="EXODIST/Object-HashBase-0.001"
>0.001
  (EXODIST on 2016-12-09)</option>
</optgroup>
</select>
    </li>
    <li class="version-diff">
<select onchange="document.location.href='/release/EXODIST/Object-HashBase-0.010/diff/' + encodeURIComponent(this.value) + '/lib/Object/HashBase.pm'
" class="form-control tool-bar-form">
  <option disabled selected>Diff with version</option>
<option
  disabled
  value="EXODIST/Object-HashBase-0.010"
>0.010
  (EXODIST on 2023-10-23)</option>
<option
  
  value="EXODIST/Object-HashBase-0.009"
>0.009
  (EXODIST on 2020-01-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="EXODIST/Object-HashBase-0.008"
>0.008
  (EXODIST on 2019-09-24)</option>
<option
  
  value="EXODIST/Object-HashBase-0.007"
>0.007
  (EXODIST on 2019-09-19)</option>
<option
  
  value="EXODIST/Object-HashBase-0.006"
>0.006
  (EXODIST on 2017-10-21)</option>
<option
  
  value="EXODIST/Object-HashBase-0.005"
>0.005
  (EXODIST on 2017-02-11)</option>
<option
  
  value="EXODIST/Object-HashBase-0.004-TRIAL"
>0.004-TRIAL DEV
  (EXODIST on 2017-02-10)</option>
<option
  
  value="EXODIST/Object-HashBase-0.003"
>0.003
  (EXODIST on 2016-12-11)</option>
<option
  
  value="EXODIST/Object-HashBase-0.002"
>0.002
  (EXODIST on 2016-12-09)</option>
<option
  
  value="EXODIST/Object-HashBase-0.001"
>0.001
  (EXODIST on 2016-12-09)</option>
</optgroup>
</select>
    </li>

    <li>
<ul class="dependencies">
  <li class="nav-header">Dependencies</li>
  <li><i>none</i></li>
  <li>
    <hr>
  </li>
  <li>
    <a href="https://metacpan.org/module/Object::HashBase/requires">Reverse dependencies</a>
  </li>
  <li>
    <a href="http://deps.cpantesters.org/?module=Object%3A%3AHashBase">CPAN Testers List</a>
  </li>
  <li>
    <a href="https://cpandeps.grinnz.com/?dist=Object-HashBase">Dependency graph</a>
  </li>
</ul>
    </li>
    <li class="nav-header">Permalinks</li>
    <li>
      <a href="https://metacpan.org/release/EXODIST/Object-HashBase-0.010/view/lib/Object/HashBase.pm">This version</a>
    </li>
    <li>
      <a href="./Object::HashBase.html">Latest version</a>
    </li>
    <li>
<div class="plussers">
<div class="nav-header">++ed by:</div>
<div>
<a class="display-all" href="https://metacpan.org/author/MHOWARD"><img src="https://www.gravatar.com/avatar/23ac2fbc91ec185f5da16627eb556667?d=identicon&amp;s=20" title="MHOWARD" alt="MHOWARD"></a>
</div>
<!-- Display counts of plussers-->
<div>
    <a href="https://metacpan.org/dist/Object-HashBase/plussers">1 PAUSE user</a>
</div>
</div>
    </li>
    <li>
    </li>
              </ul>
            </div>
          </nav>
          <div class="content-navigation">
<div class="breadcrumbs">
  <span>
    <a data-keyboard-shortcut="g a" rel="author" href="https://metacpan.org/author/EXODIST" class="author-name">Chad Granum</a>
  </span>
  <span>&nbsp;/&nbsp;</span>
  <div class="release dist-release status-latest maturity-released">
    <span class="dropdown"><b class="caret"></b></span>
<select onchange="document.location.href=&#39;/release/&#39;+this.value+&#39;/view/lib/Object/HashBase.pm&#39;" class="">
<option
  selected
  value="EXODIST/Object-HashBase-0.010"
>0.010
  (EXODIST on 2023-10-23)</option>
<option
  
  value="EXODIST/Object-HashBase-0.009"
>0.009
  (EXODIST on 2020-01-17)</option>
<optgroup label="BackPAN">'
<option
  
  value="EXODIST/Object-HashBase-0.008"
>0.008
  (EXODIST on 2019-09-24)</option>
<option
  
  value="EXODIST/Object-HashBase-0.007"
>0.007
  (EXODIST on 2019-09-19)</option>
<option
  
  value="EXODIST/Object-HashBase-0.006"
>0.006
  (EXODIST on 2017-10-21)</option>
<option
  
  value="EXODIST/Object-HashBase-0.005"
>0.005
  (EXODIST on 2017-02-11)</option>
<option
  
  value="EXODIST/Object-HashBase-0.004-TRIAL"
>0.004-TRIAL DEV
  (EXODIST on 2017-02-10)</option>
<option
  
  value="EXODIST/Object-HashBase-0.003"
>0.003
  (EXODIST on 2016-12-11)</option>
<option
  
  value="EXODIST/Object-HashBase-0.002"
>0.002
  (EXODIST on 2016-12-09)</option>
<option
  
  value="EXODIST/Object-HashBase-0.001"
>0.001
  (EXODIST on 2016-12-09)</option>
</optgroup>
</select>
    <a data-keyboard-shortcut="g d" class="release-name" href="https://metacpan.org/dist/Object-HashBase">Object-HashBase-0.010</a>
  </div>
<span class="river-gauge-gauge">
  <svg width="24px"
       height="15px"
       version="1.1"
       xmlns="http://www.w3.org/2000/svg"
       xmlns:xlink="http://www.w3.org/1999/xlink">

    <g>
      <title>        River stage zero &#10;
          No dependents
      </title>

      <rect x="0"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="5"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="10"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="15"  y="0" width="4" height="15" fill="#e4e2e2" />
      <rect x="20"  y="0" width="4" height="15" fill="#e4e2e2" />
    </g>
  </svg>

</span>
<div id="Object-HashBase-fav" class="logged_in">
<form action="https://metacpan.org/account/favorite/add" style="display: inline" onsubmit="return favDistribution(this)">
    <input type="hidden" name="remove" value="0">
    <input type="hidden" name="release" value="Object-HashBase-0.010">
    <input type="hidden" name="author" value="EXODIST">
    <input type="hidden" name="distribution" value="Object-HashBase">
    <button type="submit" class="favorite highlight"><span>1</span> ++</button>
</form>
</div>
<div class="logged_out">
<a href="./Object::HashBase.html" onclick="alert('Please sign in to add favorites'); return false" class="favorite highlight">
<span>1</span> ++</a>
</div>
   / <span>Object::HashBase</span>
</div>
          </div>
          <main class="content">


<nav class="toc">
  <div class="toc-header"><strong>Contents</strong></div>
<ul>
  <li><a href="./Object::HashBase.html#NAME">NAME</a></li>
  <li><a href="./Object::HashBase.html#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="./Object::HashBase.html#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="./Object::HashBase.html#INCLUDING-IN-YOUR-DIST">INCLUDING IN YOUR DIST</a></li>
  <li><a href="./Object::HashBase.html#METHODS">METHODS</a>
    <ul>
      <li><a href="./Object::HashBase.html#PROVIDED-BY-HASH-BASE">PROVIDED BY HASH BASE</a></li>
      <li><a href="./Object::HashBase.html#HOOKS">HOOKS</a></li>
    </ul>
  </li>
  <li><a href="./Object::HashBase.html#ACCESSORS">ACCESSORS</a>
    <ul>
      <li><a href="./Object::HashBase.html#READ/WRITE">READ/WRITE</a></li>
      <li><a href="./Object::HashBase.html#READ-ONLY">READ ONLY</a></li>
      <li><a href="./Object::HashBase.html#DEPRECATED-SETTER">DEPRECATED SETTER</a></li>
      <li><a href="./Object::HashBase.html#NO-SETTER">NO SETTER</a></li>
      <li><a href="./Object::HashBase.html#NO-READER">NO READER</a></li>
      <li><a href="./Object::HashBase.html#CONSTANT-ONLY">CONSTANT ONLY</a></li>
    </ul>
  </li>
  <li><a href="./Object::HashBase.html#SUBCLASSING">SUBCLASSING</a></li>
  <li><a href="./Object::HashBase.html#GETTING-A-LIST-OF-ATTRIBUTES-FOR-A-CLASS">GETTING A LIST OF ATTRIBUTES FOR A CLASS</a></li>
  <li><a href="./Object::HashBase.html#SOURCE">SOURCE</a></li>
  <li><a href="./Object::HashBase.html#MAINTAINERS">MAINTAINERS</a></li>
  <li><a href="./Object::HashBase.html#AUTHORS">AUTHORS</a></li>
  <li><a href="./Object::HashBase.html#COPYRIGHT">COPYRIGHT</a></li>
</ul></nav>
<div class="pod anchors">
<h1 id="NAME">NAME</h1>

<p>Object::HashBase - Build hash based classes.</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<p>A class:</p>

<pre><code>    package My::Class;
    use strict;
    use warnings;

    # Generate 3 accessors
    use Object::HashBase qw/foo -bar ^baz &lt;bat &gt;ban +boo/;

    # Chance to initialize defaults
    sub init {
        my $self = shift;    # No other args
        $self-&gt;{+FOO} ||= &quot;foo&quot;;
        $self-&gt;{+BAR} ||= &quot;bar&quot;;
        $self-&gt;{+BAZ} ||= &quot;baz&quot;;
        $self-&gt;{+BAT} ||= &quot;bat&quot;;
        $self-&gt;{+BAN} ||= &quot;ban&quot;;
        $self-&gt;{+BOO} ||= &quot;boo&quot;;
    }

    sub print {
        print join &quot;, &quot; =&gt; map { $self-&gt;{$_} } FOO, BAR, BAZ, BAT, BAN, BOO;
    }</code></pre>

<p>Subclass it</p>

<pre><code>    package My::Subclass;
    use strict;
    use warnings;

    # Note, you should subclass before loading HashBase.
    use base &#39;My::Class&#39;;
    use Object::HashBase qw/bub/;

    sub init {
        my $self = shift;

        # We get the constants from the base class for free.
        $self-&gt;{+FOO} ||= &#39;SubFoo&#39;;
        $self-&gt;{+BUB} ||= &#39;bub&#39;;

        $self-&gt;SUPER::init();
    }</code></pre>

<p>use it:</p>

<pre><code>    package main;
    use strict;
    use warnings;
    use My::Class;

    # These are all functionally identical
    my $one   = My::Class-&gt;new(foo =&gt; &#39;MyFoo&#39;, bar =&gt; &#39;MyBar&#39;);
    my $two   = My::Class-&gt;new({foo =&gt; &#39;MyFoo&#39;, bar =&gt; &#39;MyBar&#39;});
    my $three = My::Class-&gt;new([&#39;MyFoo&#39;, &#39;MyBar&#39;]);

    # Readers!
    my $foo = $one-&gt;foo;    # &#39;MyFoo&#39;
    my $bar = $one-&gt;bar;    # &#39;MyBar&#39;
    my $baz = $one-&gt;baz;    # Defaulted to: &#39;baz&#39;
    my $bat = $one-&gt;bat;    # Defaulted to: &#39;bat&#39;
    # &#39;&gt;ban&#39; means setter only, no reader
    # &#39;+boo&#39; means no setter or reader, just the BOO constant

    # Setters!
    $one-&gt;set_foo(&#39;A Foo&#39;);

    #&#39;-bar&#39; means read-only, so the setter will throw an exception (but is defined).
    $one-&gt;set_bar(&#39;A bar&#39;);

    # &#39;^baz&#39; means deprecated setter, this will warn about the setter being
    # deprecated.
    $one-&gt;set_baz(&#39;A Baz&#39;);

    # &#39;&lt;bat&#39; means no setter defined at all
    # &#39;+boo&#39; means no setter or reader, just the BOO constant

    $one-&gt;{+FOO} = &#39;xxx&#39;;</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>This package is used to generate classes based on hashrefs. Using this class will give you a <code>new()</code> method, as well as generating accessors you request. Generated accessors will be getters, <code>set_ACCESSOR</code> setters will also be generated for you. You also get constants for each accessor (all caps) which return the key into the hash for that accessor. Single inheritance is also supported.</p>

<h1 id="INCLUDING-IN-YOUR-DIST"><a id="INCLUDING"></a>INCLUDING IN YOUR DIST</h1>

<p>If you want to use HashBase, but do not want to depend on it, you can include it in your distribution.</p>

<pre><code>    $ hashbase_inc.pl Prefix::For::Module</code></pre>

<p>This will create 2 files:</p>

<pre><code>    lib/Prefix/For/Module/HashBase.pm
    t/HashBase.t</code></pre>

<p>You can then use the includes <code>Prefix::For::Module::HashBase</code> instead of <code>Object::HashBase</code>.</p>

<p>You can re-run this script to regenerate the files, or upgrade them to newer versions.</p>

<p>If the script was not installed, it can be found in the <code>scripts/</code> directory.</p>

<h1 id="METHODS">METHODS</h1>

<h2 id="PROVIDED-BY-HASH-BASE"><a id="PROVIDED"></a>PROVIDED BY HASH BASE</h2>

<dl>

<dt id="$it-=-$class-&gt;new(%PAIRS)"><a id="it----class--new-PAIRS"></a>$it = $class-&gt;new(%PAIRS)</dt>
<dd>

</dd>
<dt id="$it-=-$class-&gt;new(\%PAIRS)"><a id="it----class--new-PAIRS1"></a>$it = $class-&gt;new(\%PAIRS)</dt>
<dd>

</dd>
<dt id="$it-=-$class-&gt;new(\@ORDERED_VALUES)"><a id="it----class--new-ORDERED_VALUES"></a>$it = $class-&gt;new(\@ORDERED_VALUES)</dt>
<dd>

<p>Create a new instance.</p>

<p>HashBase will not export <code>new()</code> if there is already a <code>new()</code> method in your packages inheritance chain.</p>

<p><b>If you do not want this method you can define your own</b> you just have to declare it before loading <a href="./Object::HashBase.html">Object::HashBase</a>.</p>

<pre><code>    package My::Package;

    # predeclare new() so that HashBase does not give us one.
    sub new;

    use Object::HashBase qw/foo bar baz/;

    # Now we define our own new method.
    sub new { ... }</code></pre>

<p>This makes it so that HashBase sees that you have your own <code>new()</code> method. Alternatively you can define the method before loading HashBase instead of just declaring it, but that scatters your use statements.</p>

<p>The most common way to create an object is to pass in key/value pairs where each key is an attribute and each value is what you want assigned to that attribute. No checking is done to verify the attributes or values are valid, you may do that in <code>init()</code> if desired.</p>

<p>If you would like, you can pass in a hashref instead of pairs. When you do so the hashref will be copied, and the copy will be returned blessed as an object. There is no way to ask HashBase to bless a specific hashref.</p>

<p>In some cases an object may only have 1 or 2 attributes, in which case a hashref may be too verbose for your liking. In these cases you can pass in an arrayref with only values. The values will be assigned to attributes in the order the attributes were listed. When there is inheritance involved the attributes from parent classes will come before subclasses.</p>

</dd>
</dl>

<h2 id="HOOKS">HOOKS</h2>

<dl>

<dt id="$self-&gt;init()"><a id="self--init"></a>$self-&gt;init()</dt>
<dd>

<p>This gives you the chance to set some default values to your fields. The only argument is <code>$self</code> with its indexes already set from the constructor.</p>

<p><b>Note:</b> Object::HashBase checks for an init using <code>$class-&gt;can(&#39;init&#39;)</code> during construction. It DOES NOT call <code>can()</code> on the created object. Also note that the result of the check is cached, it is only ever checked once, the first time an instance of your class is created. This means that adding an <code>init()</code> method AFTER the first construction will result in it being ignored.</p>

</dd>
</dl>

<h1 id="ACCESSORS">ACCESSORS</h1>

<h2 id="READ/WRITE"><a id="READ"></a><a id="READ-WRITE"></a>READ/WRITE</h2>

<p>To generate accessors you list them when using the module:</p>

<pre><code>    use Object::HashBase qw/foo/;</code></pre>

<p>This will generate the following subs in your namespace:</p>

<dl>

<dt id="foo()"><a id="foo"></a>foo()</dt>
<dd>

<p>Getter, used to get the value of the <code>foo</code> field.</p>

</dd>
<dt id="set_foo()"><a id="set_foo"></a>set_foo()</dt>
<dd>

<p>Setter, used to set the value of the <code>foo</code> field.</p>

</dd>
<dt id="FOO()"><a id="FOO"></a>FOO()</dt>
<dd>

<p>Constant, returns the field <code>foo</code>&#39;s key into the class hashref. Subclasses will also get this function as a constant, not simply a method, that means it is copied into the subclass namespace.</p>

<p>The main reason for using these constants is to help avoid spelling mistakes and similar typos. It will not help you if you forget to prefix the &#39;+&#39; though.</p>

</dd>
</dl>

<h2 id="READ-ONLY"><a id="READ1"></a>READ ONLY</h2>

<pre><code>    use Object::HashBase qw/-foo/;</code></pre>

<dl>

<dt id="set_foo()1"><a id="set_foo1"></a>set_foo()</dt>
<dd>

<p>Throws an exception telling you the attribute is read-only. This is exported to override any active setters for the attribute in a parent class.</p>

</dd>
</dl>

<h2 id="DEPRECATED-SETTER"><a id="DEPRECATED"></a>DEPRECATED SETTER</h2>

<pre><code>    use Object::HashBase qw/^foo/;</code></pre>

<dl>

<dt id="set_foo()2"><a id="set_foo2"></a>set_foo()</dt>
<dd>

<p>This will set the value, but it will also warn you that the method is deprecated.</p>

</dd>
</dl>

<h2 id="NO-SETTER"><a id="NO"></a>NO SETTER</h2>

<pre><code>    use Object::HashBase qw/&lt;foo/;</code></pre>

<p>Only gives you a reader, no <code>set_foo</code> method is defined at all.</p>

<h2 id="NO-READER"><a id="NO1"></a>NO READER</h2>

<pre><code>    use Object::HashBase qw/&gt;foo/;</code></pre>

<p>Only gives you a write (<code>set_foo</code>), no <code>foo</code> method is defined at all.</p>

<h2 id="CONSTANT-ONLY"><a id="CONSTANT"></a>CONSTANT ONLY</h2>

<pre><code>    use Object::HashBase qw/+foo/;</code></pre>

<p>This does not create any methods for you, it just adds the <code>FOO</code> constant.</p>

<h1 id="SUBCLASSING">SUBCLASSING</h1>

<p>You can subclass an existing HashBase class.</p>

<pre><code>    use base &#39;Another::HashBase::Class&#39;;
    use Object::HashBase qw/foo bar baz/;</code></pre>

<p>The base class is added to <code>@ISA</code> for you, and all constants from base classes are added to subclasses automatically.</p>

<h1 id="GETTING-A-LIST-OF-ATTRIBUTES-FOR-A-CLASS"><a id="GETTING"></a>GETTING A LIST OF ATTRIBUTES FOR A CLASS</h1>

<p>Object::HashBase provides a function for retrieving a list of attributes for an Object::HashBase class.</p>

<dl>

<dt id="@list-=-Object::HashBase::attr_list($class)"><a id="list---Object::HashBase::attr_list-class"></a>@list = Object::HashBase::attr_list($class)</dt>
<dd>

</dd>
<dt id="@list-=-$class-&gt;Object::HashBase::attr_list()"><a id="list----class--Object::HashBase::attr_list"></a>@list = $class-&gt;Object::HashBase::attr_list()</dt>
<dd>

<p>Either form above will work. This will return a list of attributes defined on the object. This list is returned in the attribute definition order, parent class attributes are listed before subclass attributes. Duplicate attributes will be removed before the list is returned.</p>

<p><b>Note:</b> This list is used in the <code>$class-&gt;new(\@ARRAY)</code> constructor to determine the attribute to which each value will be paired.</p>

</dd>
</dl>

<h1 id="SOURCE">SOURCE</h1>

<p>The source code repository for HashBase can be found at <i>http://github.com/Test-More/HashBase/</i>.</p>

<h1 id="MAINTAINERS">MAINTAINERS</h1>

<dl>

<dt id="Chad-Granum-&lt;exodist@cpan.org&gt;"><a id="Chad"></a><a id="Chad-Granum--exodist-cpan.org"></a>Chad Granum &lt;exodist@cpan.org&gt;</dt>
<dd>

</dd>
</dl>

<h1 id="AUTHORS">AUTHORS</h1>

<dl>

<dt id="Chad-Granum-&lt;exodist@cpan.org&gt;1"><a id="Chad1"></a><a id="Chad-Granum--exodist-cpan.org1"></a>Chad Granum &lt;exodist@cpan.org&gt;</dt>
<dd>

</dd>
</dl>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright 2017 Chad Granum &lt;exodist@cpan.org&gt;.</p>

<p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>

<p>See <i>http://dev.perl.org/licenses/</i></p></div>

<div id="metacpan_install-instructions-dialog" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title">Module Install Instructions</h4>
      </div>
      <div class="modal-body">
        <p>To install Object::HashBase, copy and paste the appropriate command in to your terminal.</p>
        <p><a href="https://metacpan.org/dist/App-cpanminus/view/bin/cpanm">cpanm</a></p>
        <pre><code>cpanm Object::HashBase</code></pre>
        <p><a href="https://metacpan.org/pod/CPAN">CPAN shell</a></p>
        <pre><code>perl -MCPAN -e shell
install Object::HashBase</code></pre>
        <p>For more information on module installation, please visit <a href="https://www.cpan.org/modules/INSTALL.html">the detailed CPAN module installation guide</a>.</p>
      </div>
      <div class="modal-footer">
        <a href="./Object::HashBase.html#" data-dismiss="modal" class="btn">Close</a>
      </div>
    </div>
  </div>
</div>
          </main>
          <div class="content-pagination">
          </div>
        </div>
        <footer class="footer">
          <div class="footer-container">
            <div class="footer-social">
              <div class="footer-link footer-logo">
                <a href="https://metacpan.org/">
                  <img src="https://metacpan.org/static/images/metacpan-logo.svg" alt="MetaCPAN" />
                </a>
              </div>
              <a class="footer-social-link" href="https://github.com/metacpan">
                <i class="fab fa-github-square"></i>
              </a>
              <a class="footer-social-link" href="https://fosstodon.org/@metacpan">
                <i class="fab fa-mastodon"></i>
              </a>
            </div>
            <div class="footer-links">
              <div class="footer-link">
                  <a href="https://metacpan.org/about">About</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/sponsors">Sponsor</a>
              </div>
              <div class="footer-link">
                  <a href="https://grep.metacpan.org">grep::cpan</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/recent">Recent</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/about/faq">FAQ</a>
              </div>
              <div class="footer-link">
                  <a href="https://metacpan.org/tools">Tools</a>
              </div>
              <div class="footer-link">
                  <a href="https://fastapi.metacpan.org/">API</a>
              </div>
              <div class="footer-link">
                  <a href="https://www.perl.org/">Perl.org</a>
              </div>
            </div>
            <div class="footer-sponsors">
              <a class="footer-sponsor-link" target="_blank" href="https://www.bytemark.co.uk/" rel="noopener">
                <img class="footer-sponsor-bytemark" src="https://metacpan.org/static/images/sponsors/bytemark_logo.svg" alt="Bytemark logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.liquidweb.com/" rel="noopener">
                <img class="footer-sponsor-liquidweb" src="https://metacpan.org/static/images/sponsors/liquidweb_logo.png" alt="liquidweb logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://deriv.com/careers/" rel="noopener">
                <img class="footer-sponsor-deriv" src="https://metacpan.org/static/images/sponsors/deriv.svg" alt="Deriv logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://geocode.xyz" rel="noopener">
                <img class="footer-sponsor-geocode" src="https://metacpan.org/static/images/sponsors/geocodelogo.svg" alt="Geocode logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://www.fastly.com/" rel="noopener">
                <img class="footer-sponsor-fastly" src="https://metacpan.org/static/images/sponsors/fastly_logo.svg" alt="Fastly logo">
              </a>
              <a class="footer-sponsor-link" target="_blank" href="https://opencagedata.com" rel="noopener">
                <img class="footer-sponsor-opencage" src="https://metacpan.org/static/images/sponsors/open-cage.svg" alt="OpenCage logo">
              </a>
            </div>
          </div>
        </footer>
        <div class="modal fade" tabindex="-1" role="dialog" id="metacpan_keyboard-shortcuts">
          <div class="modal-dialog">
            <div class="modal-content">
              <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Keyboard Shortcuts</h4>
              </div>
              <div class="modal-body row">
<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Global</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>s</kbd>
        </td>
        <td>Focus search bar</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>?</kbd>
        </td>
        <td>Bring up this help dialog</td>
      </tr>
    </tbody>
  </table>

  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>GitHub</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>p</kbd>
        </td>
        <td>Go to pull requests</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>go to github issues (only if github is preferred repository)</td>
      </tr>
    </tbody>
  </table>
</div>

<div class="col-md-6">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>POD</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>a</kbd>
        </td>
        <td>Go to author</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>c</kbd>
        </td>
        <td>Go to changes</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>i</kbd>
        </td>
        <td>Go to issues</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>d</kbd>
        </td>
        <td>Go to dist</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>r</kbd>
        </td>
        <td>Go to repository/SCM</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>s</kbd>
        </td>
        <td>Go to source</td>
      </tr>
      <tr>
        <td class="keys">
          <kbd>g</kbd> <kbd>b</kbd>
        </td>
        <td>Go to file browse</td>
      </tr>

    </tbody>
  </table>
</div>

<div class="col-md-12">
  <table class="table keyboard-shortcuts">
    <thead>
      <tr>
        <th></th>
        <th>Search terms</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td><em>module:</em> (e.g. <a href="https://metacpan.org/search?q=module%3APlugin">module:Plugin</a>)</td>
      </tr>
      <tr>
        <td><em>distribution:</em> (e.g. <a href="https://metacpan.org/search?q=distribution%3ADancer+auth">distribution:Dancer auth</a>)</td>
      </tr>
      <tr>
        <td><em>author:</em> (e.g. <a href="https://metacpan.org/search?q=author%3ASONGMU+Redis">author:SONGMU Redis</a>)</td>
      </tr>
      <tr>
        <td><em>version:</em> (e.g. <a href="https://metacpan.org/search?q=version%3A1.00">version:1.00</a>)</td>
      </tr>
    </tbody>
  </table>
</div>
              </div>
              <div class="modal-footer"></div>
            </div>
          </div>
        </div>
    </body>
</html>
